package lib.self;

import android.app.Application;
import android.content.Context;

import lib.self.fresco.NetworkImageView;
import lib.self.network.bean.NetworkRequest;
import lib.self.utils.DeviceUtil;

/**
 * description:
 * author: Steven Xiao
 * date: 2017/4/24
 */
public abstract class AppEx extends Application {
    protected static Context sContext;

    /**
     * @return 返回getApplicationContext()
     */
    public static Context getCt() {
        return sContext;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        sContext = getApplicationContext();

        NetworkImageView.init(this, getNetworkImageCache(), (int) (DeviceUtil.getRuntimeMaxMemory() / 8));

        initHttp();

        setParams();

        initUMeng();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        NetworkImageView.clearMemoryCache();
        System.gc();
    }

    public abstract String getNetworkImageCache();

    /**
     * 设置基本参数
     */
    public abstract void setParams();

    public void initUMeng() {
    }

    public void initHttp() {
        NetworkRequest.init();
    }
}
